/**
 * Paving stone.
 * @file pavingstone.h
 * @see http://code.google.com/p/mega8-hob/source/browse/trunk/pavingstone.h
 * @author Hamish Cumming & Brian Thorne
 * @version see SVN revision number
 */
#ifndef pavingstone_h
#define pavingstone_h

#include "atto.h"
#include "paver.h"
#include "linked_list.h"
#include "colour.h"
#include "polygon.h"
#include <math.h>

/** Paving stone type */
typedef struct
{
    char * name;
    int psx;
    int psy;
    colour_t colour;
    int grey;
    int charcoal;
    int brown;
    int marble; 
} pavingstone_t;

/** Paving Stone Pattern */
typedef struct
{
    pavingstone_t stone;
    int pavingstones;
    float stone2angle;
    vector_t stone2offset;
    vector_t unitvector1;
    vector_t unitvector2;
}pavingpattern_t;



/* Paving stones */
const pavingstone_t London = {"London", 100, 200, grey, 1, 1, 0, 0};
const pavingstone_t Cobblestone = {"Cobblestone", 190, 230, grey, 1, 0, 1, 0};
const pavingstone_t Patio = {"Patio", 300, 300, grey, 1, 1, 1, 1};

/* Various paving pattern units */
const pavingpattern_t pavingunit1 = {Cobblestone, 2, -PI/2, {195, 230}, {195, -195}, {430, 40}};
const pavingpattern_t pavingunit2 = {Cobblestone, 1, 0, {0,0}, {0, 235}, {195, (int)117.5}};
const pavingpattern_t pavingunit3 = {Cobblestone, 1, 0, {0,0}, {0, 235}, {195, 0}};
const pavingpattern_t pavingunit4 = {London, 2, -PI/2, {105, 200}, {310, 100}, {205, 205}};//changed numbers
const pavingpattern_t pavingunit5 = {London, 1, 0, {0,0}, {0, 205}, {105, (int)102.5}};
const pavingpattern_t pavingunit6 = {London, 1, 0, {0,0}, {0, 205}, {105, 0}};
const pavingpattern_t pavingunit7 = {Patio, 1, 0, {0,0}, {0, 308}, {308, 154}};
const pavingpattern_t pavingunit8 = {Patio, 1, 0, {0,0}, {0, 308}, {308, 0}};

/* Function Prototypes */
/**
 * Scale a pattern by a float.
 * @param pattern To Scale
 * @param scale The number to scale by.
 * @return scaled Pattern
 */
pavingpattern_t scale_pattern(pavingpattern_t pattern, float scale);

/**
 * Lays out the pavingstones in the polygon along the given segment.
 * Assumes the segment is part of the polygon, and that the polygon is drawn clockwise.
 * @param polygon The polygon to lay the stones in
 * @param segment The edge of the polygon to lay the stones against
 * @param pattern The paving pattern to use
 * @param *stones_cut A pointer to return the number of stones that intersected the polygon
 */
int lay_pavingstones(linked_list_t * polygon, segment_t segment, pavingpattern_t pattern, int* stones_cut);


void lay_pavingstone(linked_list_t * polygon, pavingpattern_t stone, float angle, point_t point);
int pavingstone_in_table(point_t point);
void add_pavingstone_to_table(point_t point);
int pavingstone_outside_polygon(linked_list_t * polygon, pavingpattern_t stone, float angle, point_t point);
void draw_pavingstone(pavingpattern_t stone, float angle, point_t point);
void draw_segment(segment_t segment);
vector_t rotate_vector(vector_t vector, float angle);
int stone_intersects_pgon(linked_list_t * polygon, pavingpattern_t stone, float angle,point_t point);

#endif
